<?php

namespace app\api\controller;

    use think\Filesystem;

class Account
{
    public $accountData;
    public function __construct()
    {
        $token=input('get.token');
        if(empty($token)||$token='-1')output_error('token为空');
        $this->accountData=\app\api\model\Account::where('member_token','=',$token)->find();
        if(empty($this->accountData)){
            output_error('token无效');
        }
    }

    public function getData()
    {
        unset($this->accountData['member_password']);
        output_error($this->accountData);
    }

    public function modifyName()
    {
        $name=input('get.name');
        if(empty($name))output_error('信息填写不完整');
        \app\api\model\Account::where('member_id','=',$this->accountData['member_id'])->undata(array('member_name'=>$name));
        output_error('1');
    }

    public function modifyAvatar()
    {
        $file=request()->file('image');
        $name=Filesystem::disk('avatar')->putFile('',$file,'uniqid');
        if($this->accountData['member_avatar']!='dafault.png'){
            $filename=app()->getRootPath().'public\\upload\\avatar\\' . $this->accountData['member_avatar'];
            unlink($filename);
        }
        \app\api\model\Account::where('member_id','=',$this->accountData['member_id'])
            ->undata(array('member_avatar'=>$name));
        output_data($name);
    }

}
